package com.itheima.array;

import java.util.Scanner;

public class ArrayDemo2 {

    public static void main(String[] args) {

        inputScore();

    }

    //需求：录入5名学生的成绩（成绩类型为小数），并输出最高分、最低分和平均分
    public static void inputScore() {
        //动态初始化数组
        double[] scores = new double[5];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生的成绩：");
            scores[i] = sc.nextDouble();
        }

        double max = scores[0];
        double min = scores[0];
        double sum = 0;
        for (int i = 0; i < scores.length; i++) {
            double temp = scores[i];
            if (temp > max) {
                max = temp;
            }
            if (temp < min) {
                min = temp;
            }
            sum += temp;
        }
        System.out.println("最高分：" + max);
        System.out.println("最低分：" + min);
        System.out.println("平均分：" + sum / scores.length);
    }
}
